import { Component } from '@angular/core';
import { MessageService } from '@core';
import { CacheService } from '@delon/cache';
import { environment } from '@env/environment';

@Component({
  selector: 'app-chat',
  templateUrl: 'chat.component.html'
})
export class ChatComponent {
  chats = [];
  constructor(private cacheService: CacheService, private messageService: MessageService,) { 
    this.cacheService.get(`${environment.im.ctx}/imMessage/findByLast`).subscribe((res:any[])=>{
      this.chats = res
    })

    this.messageService.receive$.subscribe(res=>{
      this.chats.forEach(chat => {
        if(chat.receiver == res.receiver){
          chat.message = res;
          return false;
        }
      });
    
    });
  }

  
}
